<template>
  <div>
    <div class="container">

      <el-form :inline="true" class="demo-form-inline">
        <el-form-item label="用户名">
          <el-input v-model="username" placeholder="用户名"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input v-model="password" placeholder="密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="userLogin">user登录</el-button>
          <el-button type="primary" @click="adminLogin">admin登录</el-button>
        </el-form-item>
      </el-form>

      <el-button @click="userIsLogin">user是否登录</el-button>
      <el-button @click="tokenInfo">tokenInfo</el-button>
      <el-button @click="logout">注销</el-button>
      <el-button @click="kickout">踢下线</el-button>
      <el-button @click="disable">封禁</el-button>
      <el-button @click="disabled">踢下线+封禁</el-button>

      <el-link :underline="false">{{ token }}</el-link>
    </div>
  </div>
</template>

<script>
  import request from '@/utils/request'
  import { uploadProduct } from '@/api/product'

  export default {
    name: "userInfo",
    data() {
      return {
        username: 'user',
        password: '123',

        token: localStorage.getItem("satoken") || '',
      };
    },
    methods: {
      userLogin() {// 登录
        return request({ url: '/user/login', method: 'GET',
          params: { username: this.username, password: this.password, }
        }).then(response => {
          console.log(response)
          this.judgment(response)
          this.token = response.satoken
          localStorage.setItem("satoken", response.satoken)
        })
      },
      userIsLogin() {// 是否登录
        return request({ url: '/admin/isLogin', method: 'GET', headers: { 'satoken' : this.token, }
        }).then(response => {
          console.log(response)
          this.judgment(response)
        })
      },

      kickout() {// 是否登录
        return request({ url: '/admin/kickout', method: 'GET', headers: { 'satoken' : this.token, }
        }).then(response => {
          console.log(response)
          this.judgment(response)
        })
      },
      disable() {// 是否登录
        return request({ url: '/user/disable', method: 'GET', headers: { 'satoken' : this.token, }
        }).then(response => {
          console.log(response)
          this.judgment(response)
        })
      },
      disabled() {// 是否登录
        return request({ url: '/user/disabled', method: 'GET', headers: { 'satoken' : this.token, }
        }).then(response => {
          console.log(response)
          this.judgment(response)
        })
      },


      tokenInfo() {// 获取产品列表
        return request({
          url: '/user/tokenInfo',
          method: 'GET',
          headers: {
            'satoken' : this.token,
          }
        }).then(response => {
          console.log(response)
          this.judgment(response)
        })
      },
      logout() {// 是否登录
        return request({
          url: '/user/logout',
          method: 'GET',
          headers: {
            'satoken' : this.token,
          }
        }).then(response => {
          console.log(response)
          this.judgment(response)
        })
      },

      /* admin */
      adminLogin() {
        return request({
          url: '/admin/login',
          method: 'GET',
          params: { username: this.username, password: this.password, }
        }).then(response => {
          console.log(response)
          this.judgment(response)
        })
      },
      judgment(response){
        if (response.code === 200) {
          this.$notify.success({title: '成功',message: response.msg, duration: 1500});
        } else {
          this.$notify.warning({title: '错误',message: response.msg, duration: 1500});
        }
      },
    },
  };
</script>

